package com.probox.common.core.utils.money;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class CountFormatUtil {
    public static String formatCount(Long count) {
        if(count == null) {
            return null;
        }

        if(count < 1000) {
            return String.valueOf(count);
        }

        BigDecimal countDecimal = new BigDecimal(count);
        BigDecimal divideDecimal = null;
        String formatUnit = "";
        if(count < 10000) {
            formatUnit = "千";
            divideDecimal = new BigDecimal(1000);
        } else if(count < 100000000) {
            formatUnit = "万";
            divideDecimal = new BigDecimal(10000);
        } else if(count >= 100000000) {
            formatUnit = "亿";
            divideDecimal = new BigDecimal(100000000);
        }
        //String formatCount = countDecimal.divide(divideDecimal,1,RoundingMode.DOWN).toString().replace(".0", "") + formatUnit;
        String formatCount = countDecimal.divide(divideDecimal,1,RoundingMode.DOWN).toString() + formatUnit;
        return formatCount;
    }
}
